package cn.ywang.mybatis.old;

/**
 * @author BeatificWang
 * @date 2019/9/2 22:34
 */
public class SqlSession {

	private Configuration configuration;

	private Executor executor;

	public SqlSession(Configuration configuration, Executor executor) {
		this.configuration = configuration;
		this.executor = executor;
	}

	/**
	 * 调用执行器执行单条查询
	 *
	 * @param statementId
	 * @param parameter
	 * @param <T>
	 * @return
	 */
	public <T> T selectOne(String statementId, Object parameter) {
		String sql = Configuration.resourceBundle.getString(statementId);
		return this.executor.query(sql, parameter);
	}

	public <T> T getMapper(Class<?> clazz) {
		return this.configuration.getMapper(clazz, this);
	}
}
